# -*- coding: utf-8 -*-
"""
Created on Sat Jun  9 15:51:36 2012

@author: nzhao
"""
import numpy as np
from traits.api import Str, List, Instance

from misc.readxyz import readfile
from math_qm.CoordianteSystem import CoordinateSystem
from phy.spin.AbstractSpinSystem import AbstractSpinSystem
from phy.spin.SingleSpin import SingleSpin


class MultiSpin(AbstractSpinSystem):
    input_file = Str('')
    spin_list = List(SingleSpin)
    axes = Instance(CoordinateSystem, () )
    
    def __init__(self, mode='list', spins= [], filename = None):
        if mode is 'list':
            self.spin_list = spins
        elif mode is 'file' and filename is not None:
            self.spin_list = readfile(filename)
        else:
            print 'error. Empty spin list is built.'
        
        self.nspin  = len(self.spin_list)

    
    def dist(self, spin_i, spin_j):
        r1= self.spin_list[spin_i].postion()
        r2= self.spin_list[spin_j].postion()
        return np.linalg.norm(r1-r2)

    def dir_vect(self, spin_i, spin_j):
        r1= self.spin_list[spin_i].postion()
        r2= self.spin_list[spin_j].postion()
        return r1-r2


if __name__ == '__main__':
    spins = MultiSpin(mode='file', filename='/home/nzhao/research/computation/workspace/SpinSolver1/phy/spin/example_spin_file.spin')
    print spins.dist(0, 1)